<template>
  <div>
    <a-modal
      title="选择商品"
      :width="1200"
      :visible="visible"
      centered
      :footer='null'
      @cancel="handleCancel"
      cancelText="关闭">
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :md="6" :sm="8">
              <a-form-item label="商品名称" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}">
                <a-input placeholder="请输入" v-model="queryParam.productName" allowClear></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="商品类别" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}">
                <select-store-category v-model='queryParam.categoryId'></select-store-category>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-button type="primary" @click="searchQuery">查询</a-button>
              <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading">
        <div slot="coverImg" slot-scope="text, record">
          <j-image-upload v-model='record.coverImg' disabled></j-image-upload>
        </div>
        <span slot="action" slot-scope="text, record">
          <a @click="addTap(record)">添加</a>
        </span>
      </a-table>
    </a-modal>
  </div>

</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import SelectStoreCategory from '@comp/SelectStoreCategory/SelectStoreCategory.vue'
  export default {
    components: { SelectStoreCategory },
    mixins:[JeecgListMixin],
    data () {
      return {
        visible: false,
        queryParam: {
          status: 1
        }, // 查询条件
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title: '商品名称',
            align: 'center',
            dataIndex: 'productName'
          },
          {
            title: '封面图',
            align: 'center',
            dataIndex: 'coverImg',
            scopedSlots: { customRender: 'coverImg' },
            width: 400
          },
          {
            title: '规格',
            align: 'center',
            dataIndex: 'specStr',
            scopedSlots: { customRender: 'specStr' },
          },
          {
            title: '类别',
            align: 'center',
            dataIndex: 'categoryName'
          },
          {
            title: '库存',
            align: 'center',
            dataIndex: 'stock'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
            width: 100
          }
        ], // 表头
        url: {
          list: "/product/jwhProduct/list",
        },
      }
    },
    methods: {
      add () {
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      },
      addTap(record) {
        this.visible = false;
        this.$emit('change', record);
      }
    }
  }
</script>

<style scoped lang='less'>
.code {
  img {
    width: 500px;
    display: block;
    margin: 0 auto;
  }
}

</style>